﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CJFirewall.View;

namespace CJFirewall
{
    /// <summary>
    /// MainHome.xaml 的交互逻辑
    /// </summary>
    public partial class MainHome : Window
    {
        private ConnectionView PageOne=null;
        private AppConnection PageTwo = null;
        private AccessControlList PageThree = null;
        private About PageFour = null;
        public MainHome()
        {
            InitializeComponent();
            GetInfoButton_Click(null,null);
        }

        private void Window_DragMove(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

         private void MinButton_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState= WindowState.Minimized;
        }

        private void MaxButton_Click(object sender, RoutedEventArgs e)
        {
            if(this.WindowState== WindowState.Normal)
                this.WindowState = WindowState.Maximized;
            else
                this.WindowState = WindowState.Normal;
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            Process[] All = Process.GetProcesses();
            foreach (var ps in All)
            {
                if (ps.ProcessName == "ACLKernel")
                {
                    ps.Kill();
                    break;
                }
            }
            this.Close();
        }

        private void GetInfoButton_Click(object sender, RoutedEventArgs e)
        {
            if (PageOne == null)
                PageOne = new ConnectionView();
            HomePage.Content = PageOne;
        }
        private void APP_Button(object sender, RoutedEventArgs e)
        {
            if (PageTwo == null)
                PageTwo = new AppConnection();
            HomePage.Content = PageTwo;
        }

        private void ACL_Click(object sender, RoutedEventArgs e)
        {
            if (PageThree == null)
                PageThree = new AccessControlList();
            HomePage.Content = PageThree;
        }

        private void About_Click(object sender, RoutedEventArgs e)
        {
            if (PageFour == null)
                PageFour = new About();
            HomePage.Content = PageFour;
        }
    }
}
